
import hxd.Timer;
import hxd.Rand;
import udprotean.shared.Utils;
import h2d.Camera;
import h2d.col.Point;
import h2d.Flow;
import h3d.Vector;
import hxd.fmt.grd.Data.Color;
import sdl.Window;
import h2d.Bitmap;
import hxd.res.Image;
import format.abc.Data.Init;
import Xml.XmlType;
import cdb.Data;
import hxd.File;
import ui.View_Town;
import tree.Root;
import format.agal.Data.Tex;
import h2d.Font;
import h2d.Text;
import h2d.Object;
import ui.View_Start;
import ui.ViewTress;
import hxd.App;



// 2021.2.10 - 2021.2.17
class Main extends App {
    private static var m_instance : Main;
    public var UIRoot : Object;
    public var node : Dynamic;
    private var root_follow : Object;//跟随相机的根物体
    public static var Height = 720;
    public static var Width = 1280;
    public static var H_W = cast(Height, Float) / Width;
    public static function GetInstance() {
        return m_instance;
    }

    
	static function main() {

        hxd.res.Resource.LIVE_UPDATE = true;
        Res.initLocal();
        m_instance = new Main();
       
	}

    override function onResize() {
        super.onResize();

        var window = hxd.Window.getInstance();
        var sw = window.width / cast(Main.Width, Float);
        var sh = window.height / cast(Main.Height, Float);
        var s = Math.min(sw, sh);
        UIRoot.scaleX = s;
        UIRoot.scaleY = s;
        var x = 0.0;
        var y = 0.0;
        if(sh > sw){
            y = window.height - window.width * H_W;
            y *= 0.5;
        }
        else {
            x = window.width - window.height / H_W;
            x *= 0.5;
        }
        UIRoot.setPosition(x, y);
    }

    override function init() {
        super.init();
        trace("init");
        root_follow = new Object(s2d);
        UIRoot = new Object(root_follow);
        onResize();

        node = new View_Town();
        node.OnEnter(null);
        LData.load(Res.load("cdb/game.cdb").toText());
    }
   
    
    override function update(dt:Float) {
        super.update(dt);
        node.OnUpdate(null);
        root_follow.setPosition(s2d.camera.x , s2d.camera.y );
        root_follow.rotation = s2d.camera.rotation; 
    }
   
}


